package com.mini.gateway.web.controller;

import com.mini.gateway.web.domain.LayTableResult;
import com.mini.gateway.core.modules.apis.service.ApiService;
import com.mini.gateway.core.modules.route.dto.RouteView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;

import java.util.HashMap;
import java.util.List;

/**
 * PageController
 *
 */
@Controller
@RequestMapping("/gateway/api")
public class ApiController {

    @Autowired
    private DiscoveryClient discoveryClient;
    @Autowired
    private ApiService apiService;

    @GetMapping("/page/list")
    public Mono<String> toListPage(final Model model) {
        List<String> serviceList = discoveryClient.getServices();
        model.addAttribute("serviceList", serviceList);
        HashMap<String, Object> dataMap = apiService.getPath("tenbent-nsc-admin");
        model.addAttribute("dataMap", dataMap);
        return Mono.create(monoSink -> monoSink.success("api/api_list"));
    }

    @GetMapping(value = "/data/list")
    @ResponseBody
    public Mono<LayTableResult<RouteView>> listData(String instanceName) {
        return Mono.just(LayTableResult.success());
    }

}
